/**
 * 
 */
package cs342.project1.mathNotebook.gui;

import java.io.File;

import javax.swing.filechooser.FileFilter;

/**
 * @author aaron
 *
 */
public class StringFileFilter extends FileFilter {
	protected String extension;
	protected String description;
	public StringFileFilter(String extension, String name) {
		this.extension = extension;
		this.description = name;
	}

	public boolean accept(File f) 
	{
	  if (f.isDirectory()) 
	    return true;
	
	  if (this.extension.equals(getExtension(f))) 
	       return true; 

	    return false;
	}
	    
	public String getDescription() 
	{
	    return this.description;
	}

	public static String getExtension(File f) 
	{
	  String s = f.getName();
	  int i = s.lastIndexOf('.');
	  if (i > 0 &&  i < s.length() - 1) 
	    return s.substring(i+1).toLowerCase();
	  return "";
	}
}
